990D - Graph And Its Complement - CodeForces Solution


constructive algorithms graphs implementation *1700

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>

using namespace std;



/*----------------------------------------PBDS-----------------------------------------*/

//order_of_key (k) : Number of items strictly smaller than k .

//find_by_order(k) : K-th element in a set (counting from zero).



//#include <ext/pb_ds/assoc_container.hpp>

//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;

//template<typename T> using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

//template<typename T> using indexed_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*-------------------------------------------------------------------------------------

*/

/*----------------------------------------MACROS---------------------------------------*/

#define fs                      first

#define se                      second

#define ll                      long long

#define pb                      push_back

#define ppb                     pop_back

#define nl                      (string)"\n"

#define sz(x)                   (int)x.size()

#define all(x)                  x.begin(), x.end()

#define rall(x)                 x.rbegin(), x.rend()

#define sortall(x)              sort(all(x))

#define rsort(x)                sort(rall(x))

#define mp(x,y)                 make_pair(x,y)

#define prec(n)                 fixed<<setprecision(n)

#define fra(i, x)               for (auto &i : x)

#define fr(i, x, y)             for (int i = (int)x; i < (int)y; ++i)

#define frr(i, x, y)            for (int i = (int)x; i >= (int)y; --i)



typedef pair<ll, ll>            pll;

typedef pair<int, int>          pii;

typedef vector<ll>              vl;

typedef vector<int>             vi;

typedef vector<vi>              vvi;

typedef vector<vl>              vvl;

typedef vector<pii>             vpi;

typedef vector<pll>             vpl;

typedef vector<bool>            vb;

typedef vector<string>          vs;

/*-------------------------------------------------------------------------------------*/



/*--------------------------------------DEGUG------------------------------------------*/

#ifndef ONLINE_JUDGE

#define debug(x...) cout << #x<<" = "; wrt(x); wrt();

#define ____divider____ cout << "-------output-------\n"

#else

#define debug(x...)

#define ____divider____

#endif

/*-------------------------------------------------------------------------------------*/



/*---------------------------------------I/O-------------------------------------------*/

void read() { return; }

void wrt() { cout << nl; }

void wrt(ll t) {cout << t ;}

void wrt(int t) {cout << t ;}

void wrt(char t) {cout << t ;}

void wrt(string t) {cout << t ;}

void wrt(double t) {cout << t ;}

template <class T> void wrt(set <T> v);

template <class T> void wrt(vector <T> v);

template <class T> void wrt(multiset <T> v);

template <class T, class V> void wrt(map <T, V> v);

template <class T, class V> void wrt(pair <T, V> p);

template <size_t T> void wrt(const char (&a)[T]) { string s=a; wrt(s); wrt(); }

template <class T> void wrt(set <T> v) { for (T i : v) {wrt(i); wrt(' ');} wrt(); }

template <class T> void wrt(vector <T> v) { for (T i : v) {wrt(i); wrt(' ');} wrt(); }

template <class T> void wrt(multiset <T> v) { for (T i : v) {wrt(i); wrt(' ');} wrt(); }

template <class T, class V> void wrt(map <T, V> v){for(auto i:v){wrt(i);wrt(' ');}wrt();}

template <class T, class V> void wrt(pair <T, V> p){wrt(p.fs); wrt(' ');wrt(p.se);wrt();}

template <class T, class... V> void wrt(T x, V... args){(wrt(x), wrt(' '),wrt(args...));}

template <class T, class... V> void read(T &x, V &...args) { ((cin >> x),read(args...));}

template <class T> void readArr(T &arr, int x, int y) { fr(i, x, y) cin >> arr[i]; }

template <class T> void wrtArr(T &arr, int x, int y){fr(i, x, y)cout<<arr[i]<<' ';wrt();}

/*-------------------------------------------------------------------------------------*/



/*----------------------------------------CONST----------------------------------------*/

//int MOD = 0;

const int N = 2e5+7;

const int INF = 2e9;

//const ll INF = 2e15;

const int MOD = 1e9+7;

//const int MOD = 998244353;

const double PI = 3.14159265358979312;

const int dir[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};     // {x, y}

/*-------------------------------------------------------------------------------------*/



/*----------------------------------------FUNCT----------------------------------------*/

template<class T> ll _sum(vector<T>& arr) { return accumulate(all(arr), 0ll); }

template<class T> bool _min(T &a, T b) { return a > b ? (a = b, true) : false; }

template<class T> bool _max(T &a, T b) { return a < b ? (a = b, true) : false; }

ll _bits(ll x) { ll cnt = 0; while(x>0) { cnt++; x>>=1; } return cnt; }

ll _setbits(ll x) { ll cnt = 0; while(x>0) { if(x&1) cnt++; x>>=1; } return cnt;}

ll _gcd(ll a, ll b) { return (b == 0) ? (a) : (_gcd(b, a %= b)); }

ll _lcm(ll a, ll b) { if (a < b) swap(a, b); return a / _gcd(a, b) * b; }

ll _add(ll x, ll y) { x %= MOD, y %= MOD; return (x + y) % MOD; }

ll _sub(ll x, ll y) { x %= MOD, y %= MOD; return (x - y + MOD) % MOD; }

ll _mul(ll x, ll y) { x %= MOD, y %= MOD; return (x * 1ll * y) % MOD; }

ll _pow(ll x, ll y) { if (y == 0) return 1; else if (y % 2 == 0){ 

ll _tmp=_pow(x, y / 2); return _mul(_tmp, _tmp);} else return _mul(x, _pow(x, y - 1));}

ll _inv(ll p) { return _pow(p, MOD - 2); }

ll _div(ll x, ll y) { x %= MOD, y %= MOD; return _mul(x, _inv(y)); }

ll _nCr(ll n, ll r, vl & fact){ return _mul(fact[n], _inv(_mul(fact[r], fact[n - r])));}

/*-------------------------------------------------------------------------------------*/



/*----------------------------------------MAIN-CODE------------------------------------*/



void solveTestCase(int test_case){



    int n, a, b; read(n, a, b);

    if(n==2 && a==1 && b==1) return wrt("NO");

    if(n==3 && a==1 && b==1) return wrt("NO");

    if(a>1){

        if(b==1){

            wrt("YES");

            vs ans(n, string(n, '0'));

            fr(i, a-1, n){

                fr(j, i+1, n) ans[i][j]=ans[j][i]='1';

            }

            wrt(ans);

        }else{

            wrt("NO");

        }

    }else{

        wrt("YES");

        vs ans(n, string(n, '0'));

        if(b==1){

            fr(i, 0, n-1) ans[i][(i+1)%n]=ans[(i+1)%n][i]='1';

        }else{

            fr(i, 0, b-1){

                fr(j, 0, n) ans[i][j]=ans[j][i]='1';

            }

        }

        fr(i, 0, n) ans[i][i]='0';

        wrt(ans);

    }

}



int main(){

    ios_base::sync_with_stdio(0);

    cin.tie(0), cout.tie(0);

    ____divider____;

    int test_cases=1;

    // cin>>test_cases;

    for(int t=1; t<=test_cases; t++)

        solveTestCase(t);

    return 0;

}


Comments

Submit
0 Comments
More Questions

Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations
1356. Sort Integers by The Number of 1 Bits
922. Sort Array By Parity II
344. Reverse String
1047. Remove All Adjacent Duplicates In String
977. Squares of a Sorted Array